/*    */ package com.zimbra.cs.dav.service.method;
/*    */ 
/*    */ import com.zimbra.common.service.ServiceException;
/*    */ import com.zimbra.cs.dav.DavContext;
/*    */ import com.zimbra.cs.dav.DavException;
/*    */ import com.zimbra.cs.dav.resource.Collection;
/*    */ import com.zimbra.cs.dav.resource.DavResource;
/*    */ import com.zimbra.cs.dav.resource.MailItemResource;
/*    */ import com.zimbra.cs.dav.resource.Notebook;
/*    */ import com.zimbra.cs.dav.service.DavMethod;
/*    */ import com.zimbra.cs.mailbox.MailItem.Type;
/*    */ import java.io.IOException;
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ public class Move
/*    */   extends DavMethod
/*    */ {
/*    */   public static final String MOVE = "MOVE";
/*    */   
/* 36 */   public String getName() { return "MOVE"; }
/*    */   
/* 38 */   protected MailItemResource mir = null;
/* 39 */   protected Collection col = null;
/*    */   
/*    */   public void checkPrecondition(DavContext ctxt) throws DavException, ServiceException
/*    */   {
/* 43 */     super.checkPrecondition(ctxt);
/* 44 */     DavResource rs = ctxt.getRequestedResource();
/* 45 */     if (!(rs instanceof MailItemResource))
/* 46 */       throw new DavException("cannot move", 400, null);
/* 47 */     this.col = ctxt.getDestinationCollection();
/* 48 */     this.mir = ((MailItemResource)rs);
/* 49 */     if (!this.mir.isCollection()) {
/* 50 */       Collection srcCollection = ctxt.getRequestedParentCollection();
/* 51 */       if ((srcCollection.getDefaultView() != MailItem.Type.UNKNOWN) && (srcCollection.getDefaultView() != this.col.getDefaultView())) {
/* 52 */         throw new DavException("cannot move to incompatible collection", 403, null);
/*    */       }
/*    */     } else {
/* 55 */       if ((((Collection)this.mir).getDefaultView() != MailItem.Type.DOCUMENT) && (((Collection)this.mir).getDefaultView() != MailItem.Type.UNKNOWN)) {
/* 56 */         throw new DavException("cannot move non-document collection", 403, null);
/*    */       }
/* 58 */       if ((this.col.getDefaultView() != MailItem.Type.UNKNOWN) && (this.col.getDefaultView() != MailItem.Type.DOCUMENT)) {
/* 59 */         throw new DavException("cannot move to incompatible collection", 403, null);
/*    */       }
/*    */     }
/*    */   }
/*    */   
/*    */   public void handle(DavContext ctxt) throws DavException, IOException, ServiceException {
/* 65 */     String newName = null;
/* 66 */     if (((this.mir instanceof Collection)) || ((this.mir instanceof Notebook)))
/* 67 */       newName = ctxt.getNewName();
/* 68 */     if (ctxt.isOverwriteSet()) {
/* 69 */       this.mir.moveORcopyWithOverwrite(ctxt, this.col, newName, true);
/*    */     } else {
/* 71 */       this.mir.move(ctxt, this.col, newName);
/*    */     }
/* 73 */     ctxt.setStatus(204);
/*    */   }
/*    */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/dav/service/method/Move.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */